package csu.rjxyg.util.impl;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;

import csu.rjxyg.factory.core.BaseFactory;
import csu.rjxyg.util.FileUtil;
import csu.rjxyg.util.LogUtil;

public class XMLUtil implements FileUtil{
	private String fileName;
	
	@Override
	public Object getBean(String beanName) {
		try{
			DocumentBuilderFactory dFactory = DocumentBuilderFactory.newInstance();
	        DocumentBuilder builder = dFactory.newDocumentBuilder();
	        Document doc;
	        File file = new File(fileName);
	        doc = builder.parse(file);
	          
	        //获取包含类名的文本节点
	        String cName;
	        NodeList nl = doc.getElementsByTagName(beanName);
	        Node temp = nl.item(0).getFirstChild();
	        cName = temp.getNodeValue();
	        Object o = Class.forName(cName).newInstance();
	        return o ;
		        
		}catch(Exception e){
			e.printStackTrace();
			System.out.println("未找到节点" + beanName);
		}
			return null;
	}

	@Override
	public void setFileName(String fileName) {
		// TODO Auto-generated method stub
		this.fileName = fileName;
	}


}
